namespace TrafficLightEmulator.Domain
{
    public class TrafficLights
    {
        public Light TheRedBulb { get; set; }
        public Light TheYellowBulb { get; set; }
        public Light TheGreenBulb { get; set; }

        private bool formRedToGreen;

        public TrafficLights()
        {
            TheRedBulb = new Light();
            TheYellowBulb = new Light();
            TheGreenBulb = new Light();

            TheRedBulb.State = LightState.On;
            formRedToGreen = true;
        }

        public bool WillNotAllowPersonToCross(Person person)
        {
            if (TheRedBulb.State == LightState.On) 
                return true;

            if (TheYellowBulb.State == LightState.On)
                return true;

            return false;
        }

        public void SwitchToNext()
        {
            if(TheRedBulb.State== LightState.On)
            {
                TheRedBulb.Switch();
                TheYellowBulb.Switch();

                formRedToGreen = true;
            }
            else if (TheYellowBulb.State == LightState.On)
            {
                TheYellowBulb.Switch();

                if (formRedToGreen)
                    TheGreenBulb.Switch();
                else
                    TheRedBulb.Switch();
            }
            else if (TheGreenBulb.State == LightState.On)
            {
                TheGreenBulb.Switch();
                TheYellowBulb.Switch();

                formRedToGreen = false;
            }
        }
    }
}